<template>
  <div class="main-container">
    <div class="query-box">
      <el-form :inline="true" :model="queryInfo" class="demo-form-inline" label-width="40px">
        <el-row>
          <el-form-item label="ID：">
            <el-input v-model="queryInfo.id" placeholder="请输入日志ID"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label=" " class="submit">
            <el-button type="primary" @click="getVisitList">筛选</el-button>
            <el-link type="primary" :underline="false" @click="resetData">清空筛选条件</el-link>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <el-table :data="visitList" style="width: 100%">
      <el-table-column label="ID" width="60" prop="id" align="center"> </el-table-column>
      <el-table-column label="控制器" prop="controller" align="center"> </el-table-column>
      <el-table-column label="方法" prop="action" align="center"> </el-table-column>
      <el-table-column label="访问IP" width="180" prop="ip" align="center"> </el-table-column>
      <el-table-column label="地区" width="240" align="center">
        <template slot-scope="scope">
          <div>{{ scope.row.country }}-{{ scope.row.region }}-{{ scope.row.city }}</div>
        </template>
      </el-table-column>
      <el-table-column label="服务商" prop="isp" width="120" align="center"></el-table-column>
      <el-table-column label="访问时间" prop="add_time" width="240" align="center"></el-table-column>
    </el-table>
    <pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :total="total"></pagination>
  </div>
</template>

<script>
import { getVisitList } from '@/api/system'
export default {
  data() {
    return {
      queryInfo: {
        id: '',
        page: 1,
        page_size: 10,
      },
      visitList: [],
      total: 0,
    }
  },
  created() {
    this.getVisitList()
  },
  methods: {
    async getVisitList() {
      const res = await getVisitList(this.queryInfo)
      if (res.code != 1) return this.$message.error(res.msg)
      // this.$message.success(res.msg)
      console.log(res.data)
      this.visitList = res.data.data
      this.total = res.data.total
    },
    resetData() {
      this.queryInfo = this.$options.data().queryInfo
      this.getVisitList()
    },
    handleSizeChange(newSize) {
      this.queryInfo.page_size = newSize
      this.getVisitList()
    },
    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage
      this.getVisitList()
    },
  },
}
</script>

<style lang="scss" scoped>
.query-box {
  margin-bottom: 20px;
  padding: 20px 40px;
  background: #f8f8f8;
  .submit {
    .el-button {
      margin-right: 20px;
    }
  }
}
::v-deep {
  .el-table__row {
    height: 60px !important;
  }
  .el-form-item__label {
    color: #99a9bf;
  }
  .jv-container {
    padding: 0 !important;
  }
  .jv-code {
    padding: 3px;
  }
}
</style>
